package com.modai.springcloud.entities;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import com.modai.springcloud.handler.Myhandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author ：modai
 * @date ：Created in 2020-12-16 21:56
 * @description：
 */
@RestController
@Slf4j
public class FlowController {

    @GetMapping("/testA")
    public String testA(){
//        try { TimeUnit.MILLISECONDS.sleep(300);} catch (InterruptedException e) {e.printStackTrace();}
        int i = 10/0;
        return "testA...........";
    }

    @GetMapping("/testB")
    @SentinelResource(value = "testB",blockHandlerClass = Myhandler.class,blockHandler = "testB_handler")
    public String testB(){
//        log.info(Thread.currentThread().getName()+".....testB");
        return "testB..........";
    }

    @GetMapping("/testHotkey")
    @SentinelResource(value = "testHotkey",blockHandler = "deal_testHotkey")
    public String hotkey(
            @RequestParam(value = "a",required = false) Integer a,
            @RequestParam(value="b",required = false) String b
            ){
        return "hotkey///////";
    }

    public String deal_testHotkey(
            @RequestParam(value = "a",required = false) Integer a,
            @RequestParam(value="b",required = false) String b,
            BlockException e
    ){
        return "ssssssss,/(ㄒoㄒ)/~~"+e.getMessage();
    }
}
